dnl
dnl configure.in helper macros
dnl

AC_DEFUN([WITH_PGSQL], [
	if test "x$PORTNAME" = "x"
  	then 
		EXTENSAO=""
	else
		EXTENSAO=".exe"
	fi
  AC_MSG_CHECKING(for pg_config executable)

  AC_ARG_WITH(pgsql, [  --with-pgsql=PATH path to pg_config binary or postgresql prefix dir], [
  if test -x $withval -a -f $withval
    then
    	PGSQL_CONFIG=$withval
    elif test -x $withval/bin/pg_config$EXTENSAO -a -f $withval/bin/pg_config$EXTENSAO
    then
    	PGSQL_CONFIG=$withval/bin/pg_config$EXTENSAO
    fi
  ], [
 	if test -x $PREFIX/bin/pg_config$EXTENSAO -a -f $PREFIX/bin/pg_config$EXTENSAO
    then
    	PGSQL_CONFIG=$PREFIX/bin/pg_config$EXTENSAO
    elif test -x /usr/local/pgsql/bin/pg_config$EXTENSAO -a -f /usr/local/pgsql/bin/pg_config$EXTENSAO
    then
      PGSQL_CONFIG=/usr/local/pgsql/bin/pg_config$EXTENSAO
    elif test -x /usr/bin/pg_config$EXTENSAO -a -f /usr/bin/pg_config$EXTENSAO
    then
      PGSQL_CONFIG=/usr/bin/pg_config$EXTENSAO
    fi
  ])
  if test "x$PGSQL_CONFIG" = "x"
  then
    AC_MSG_RESULT(not found)
    exit 3
  else
    AC_MSG_RESULT($PGSQL_CONFIG)
    AC_PROG_CC
    AC_PROG_CXX

    # add regular MySQL C flags
    ADDFLAGS=`$PGSQL_CONFIG --cppflags`

    CFLAGS="$CFLAGS $ADDFLAGS"
    CXXFLAGS="$CXXFLAGS $ADDFLAGS"

    LDFLAGS="$LDFLAGS "`$PGSQL_CONFIG --ldflags`" -lpq "
    LDFLAGS="$LDFLAGS "`$PGSQL_CONFIG --ldflags`" -lpq "

  fi
])